﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using TjZheng.Logger.DataEntity;
using TjZheng.Framework;
using TjZheng.Logger.Business;

namespace TjZheng.CMS.Process.Business
{
    public partial class LoggerProcess
    {
        public TreeEntity BindTree(long id)
        {
            BizLogCategory objBizLogCategory = new BizLogCategory();
            LogCategory objLogCategory = objBizLogCategory.GetRecord(id);
            if (objLogCategory == null)
            {
                return null;
            }
            var objLogCategoryList = objBizLogCategory.GetList(string.Format("IDPath like '{0}%'", objLogCategory.IDPath));
            return objLogCategoryList.ConvertToTree(objLogCategory.Id);
        }
        public List<TreeEntity> BindTrees(long id)
        {
            BizLogCategory objBizLogCategory = new BizLogCategory();
            LogCategory objLogCategory = objBizLogCategory.GetRecord(id);
            if (objLogCategory == null)
            {
                return new List<TreeEntity>();
            }
            var objLogCategoryList = objBizLogCategory.GetList(string.Format("IDPath like '{0}%'", objLogCategory.IDPath));
            return objLogCategoryList.ConvertToTreeList(objLogCategory.Id) ?? new List<TreeEntity> { };
        }
        public List<TreeEntity> BindTreesWithOther(long id)
        {
            var objTreeEntityList = this.BindTrees(id);
            if (objTreeEntityList.IsNoNull())
            {
                var objRoot = objTreeEntityList.First(c => c.id == id);
                var objTreeEntity = new TreeEntity();
                objTreeEntity.id = 0;
                objTreeEntity.text = "其他日志";
                objTreeEntity.iconCls = "icon-application";
                objRoot.children.Add(objTreeEntity);
            }
            return objTreeEntityList;
        }
        public List<TreeEntity> BindTreeList(long id)
        {
            BizLogCategory objBizLogCategory = new BizLogCategory();
            LogCategory objLogCategory = objBizLogCategory.GetRecord(id);
            if (objLogCategory == null)
            {
                return new List<TreeEntity>();
            }
            var objLogCategoryList = objBizLogCategory.GetList(string.Format("IDPath like '{0}%'", objLogCategory.IDPath));
            objLogCategoryList = objLogCategoryList.Except(new List<LogCategory> { objLogCategory }).ToList();
            return objLogCategoryList.ConvertToTreeList(objLogCategory.Id) ?? new List<TreeEntity> { };
        }
    }
}
